package com.qkbb.admin.kuibu.qkbb.funcation;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.qkbb.admin.kuibu.R;
import com.qkbb.admin.kuibu.qkbb.JavaBean.FriendList;
import com.qkbb.admin.kuibu.qkbb.url.Url;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/1/27.
 */
public class GetFriendList {
    private String user_token;
//    int image[]=new int[]{R.mipmap.ake,R.mipmap.alice,R.mipmap.bobby,R.mipmap.biaoge,R.mipmap.candy,R.mipmap.chenjun,R.mipmap.chenhao,R.mipmap.xiaoming,R.mipmap.baby};


    public List<FriendList> getFriendlist(final Context context){
        user_token=SDCardHelper.loadFileFromSdCard("user_token",context);
        final List<FriendList> list=new ArrayList<FriendList>();
//        for(int i=0;i<nicknames.length;i++){
//            FriendList friend=new FriendList();
////            friend.setImage(image[i]);
//            friend.setNickname(nicknames[i]);
//            list.add(friend);
//        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                byte b[]=HttpURLConnHelper.loadByteFromURL(Url.GETFRIEND,context);
                String s=new String(b);
                Log.e("s",s);
                try {
                    JSONObject jsonObject=new JSONObject(s);
                    JSONObject jsonObject1=jsonObject.getJSONObject("data");
                    JSONArray jsonArray=jsonObject1.getJSONArray("FriendData");
                    if (jsonArray.length()==0){
                        Log.e("wu","wu");
                    }else {
                        for(int i=0;i<jsonArray.length();i++){
                            JSONObject jsonObject2=jsonArray.getJSONObject(i);
                            FriendList friendList=new FriendList();
                            friendList.setUserid(jsonObject2.getString("userid"));
                            friendList.setNickname(jsonObject2.getString("nickname"));
                            friendList.setTag(jsonObject2.getString("tag"));
                            friendList.setOrigin_nickname(jsonObject2.getString("origin_nickname"));
                            friendList.setPhoto(jsonObject2.getString("photo"));
                            list.add(friendList);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        return  list;
    }
}
